//
//  RecordAnimateView.m
//  translateAi
//
//  Created by 陈镇 on 2023/5/13.
//

#import "RecordAnimateView.h"


@interface RecordAnimateView ()
/** <#注释#>*/
@property (nonatomic, weak) NSTimer * timer;
/** <#注释#>*/
@property (nonatomic, strong) NSArray * imageList;
/** <#注释#>*/
@property (nonatomic, assign) NSInteger index;
@end
@implementation RecordAnimateView

-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        self.image = [UIImage imageNamed:@"luyin_animat_1"];
        self.imageList = @[[UIImage imageNamed:@"luyin_animat_1"],
                           [UIImage imageNamed:@"luyin_animat_2"],
                           [UIImage imageNamed:@"luyin_animat_3"],
                           [UIImage imageNamed:@"luyin_animat_4"],];
        [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
    }
    return self;
}

-(NSTimer *)timer{
    if(!_timer){
        _timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(changeImage) userInfo:nil repeats:YES];
    }
    return _timer;
}
-(void)endTimer{
    [_timer invalidate];
    _timer = nil;
}
-(void)changeImage{
    
    self.image = self.imageList[_index%4];
    self.index ++ ;
}

@end
